package com.fjec.market.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fjec.common.jxls.BreakfastExcel;
import com.fjec.common.protocol.JsonResult;
import com.fjec.common.view.RpcReturnPage;
import com.fjec.market.entity.BizPhysicalOrder;
import com.fjec.market.view.OrderItem;
import org.apache.ibatis.annotations.Param;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 041.实物订单表 服务类
 * </p>
 *
 * @author admin
 * @since 2020-09-21
 */
public interface IBizPhysicalOrderService extends IService<BizPhysicalOrder> {


    /**
     * 提交订单
     *
     * @param addressName
     * @param addressPhone
     * @param address
     * @param totalPrice
     * @param orderType
     * @param productList
     * @return
     */
    JsonResult saveOrder(String addressName, String addressPhone, String address,
                         Integer totalPrice, Integer orderType, List<OrderItem> productList);

    /**
     * 订单查询
     *
     * @param page
     * @param status 1=全部
     *               2=待付款
     *               3=待发货
     *               4=待收货
     *               5=待评价
     *               6=投诉
     * @return
     */
    JsonResult listForOrderStatus(Page page, Integer status);

    /**
     * 出售订单查询
     *
     * @param page
     * @return
     */
    JsonResult getSaleOrderList(Page page, Integer status);

    /**
     * 获取子订单信息
     *
     * @param subOrderId
     * @return
     */
    JsonResult subOrderDetail(Long subOrderId);

    /**
     * 子订单发货
     *
     * @param id
     * @param deliType
     * @param deliId
     * @param deliName
     * @param orderNum
     * @param person
     * @param phone
     * @return
     */
    JsonResult subOrderDelivery(Long id, Integer deliType, Long deliId,
                                String deliName, String orderNum, String person, String phone);

    /**
     * 货物签收
     *
     * @param id
     * @return
     */
    JsonResult subOrderSigned(Long id);

    @Transactional(rollbackFor = Throwable.class)
    String subOrderAutoSigned(Long id);

    List<Map<String, Object>> getOrderByConditions(Integer searchBy, String title, Integer busiType, Integer markCode, Integer orderType, Integer orderStatus, String startTime, String endTime, Page page);

    /**
     * 根据子订单Id获取子订单详细
     *
     * @param id
     * @return
     */
    Map<String, Object> getOrderDetailById(Long id);

    /**
     * 根据子订单Id获取相同主订单其他订单信息
     *
     * @param id
     * @return
     */
    JsonResult getSameSubOrderByOrderId(Long id, Long subId);

    List<Map<String, Object>> getSubOrdersByBusiId(Long busiId, Page page);

    /**
     * 处理未支付订单超时
     *
     * @param orderId
     */
    void handleOrderTimeout(Long orderId);

    /**
     * 获取超时的未支付订单
     *
     * @param limit
     * @param minutes
     * @return
     */
    List<Long> getTimeoutOrder(int limit, int minutes);

    List<Map<String, Object>> getTradingsByConditions(Integer searchBy, String title, Integer orderType, Integer sellerType, Integer buyerType, Page page);

    List<Map<String, Object>> getOrderComplaintsByConditions(Integer searchBy, String title, Integer busiType, Integer markCode, Integer orderType, Integer orderStatus, String startTime, String endTime, Page page);

    List<Map<String, Object>> getLongTimeUndeliveredOrders(Integer remindTime);

    void setOrderStatus(Long orderId, Integer orderStatus, Long paymentId, Integer orderType);

    List<Map<String, Object>> getOrdersToDivide(int limit, int minutes);

    void writePhyDistributionInfo(List<Map<String, Object>> ordersToDivide);

    void writeServDistributionInfo(List<Map<String, Object>> ordersToDivide);

    List<Long> getLongTimeUnsignedSubOrders(int limit);

    String doAutoRefund(Map<String, Object> so);

    List<Map<String, Object>> getAutoRefundSubOrders(int limit);

    String handleYsDeliver(Map<String, Object> orderInfo);

    String handleYsSign(Map<String, Object> orderInfo);

    List<Map<String, Object>> getServOrdersToDivide(int limit, int minutes);

    /**
     * 搜索早餐店铺订单信息
     *
     * @param page
     * @param shopId      早餐店铺Id
     * @param subOrderId  子订单Id
     * @param busiType    早餐店铺类型
     * @param orderType   订单类型
     * @param orderStatus 订单状态
     * @param startTime   开始时间
     * @param endTime     结束时间
     * @return
     */
    RpcReturnPage<Map<String, Object>> getOrderForBreakfast(Page page,
                                                            Long shopId,
                                                            Long subOrderId,
                                                            Integer busiType,
                                                            Integer orderType,
                                                            Integer orderStatus,
                                                            LocalDateTime startTime,
                                                            LocalDateTime endTime);

    /**
     * 查询早餐店铺订单信息，生成excel用
     *
     * @param shopId
     * @param busiType
     * @param startTime
     * @param endTime
     * @return
     */
    List<BreakfastExcel> getOrderForBreakfastExcel(Long shopId,
                                                   Integer busiType,
                                                   LocalDateTime startTime,
                                                   LocalDateTime endTime);
}
